# -*- coding: utf-8 -*-
import scrapy
from moviedy90.items import Moviedy90Item

class Dy90loadingSpider(scrapy.Spider):
    name = 'dy90loading'
    allowed_domains = ['www.dy90.com']
    start_urls = ['http://www.dy90.com/frim/index50.html']

    def parse(self, response):
        currentpPage_movie_item = response.xpath('//div[@class="dmList clearfix"]')
        for movie_item in currentpPage_movie_item:
            # 创建一个Movie对象
            movie = Moviedy90Item()
            # 获取电影名称并赋值title属性
            movie['name'] = movie_item.xpath('./ul/li/dl/dt/a/@title').extract()
            # 获取电影海报地址并赋值pic_url属性
            movie['pic_url'] = movie_item.xpath('./ul/li/p/a/img/@src').extract()
            # 获取电影类型
            movie['release_type'] = movie_item.xpath('./ul/li/dl/dd/p/a/span[@class="red"]/text()').extract()
            # 获取电影上映时间
            movie['release_time'] = movie_item.xpath('./ul/li/dl/dd/p/a/span[@class="green"]/text()').extract()
            # 将封装好的一个电影信息添加到容器中,yield作用是创建一个列表并添加元素
            yield movie
